import { connection } from '../app/database/mysql'
import { AvatarModel } from './avatar.model'

export const createAvatar = async (avatar: AvatarModel) => {
  const statment = `INSERT INTO avatar SET ?`
  const [data] = await connection.promise().query(statment, [avatar])
  return data
}

export const findAvatarByUserId = async (userId: number) => {
  const statement = `SELECT * FROM avatar WHERE user_id = ? ORDER BY id DESC`
  const [data] = await connection.promise().query(statement, [userId])
  return data[0]
}
